package bddPlanning;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.View;

import java.sql.SQLException;

/**
 * Created by richard on 11/02/14.
 */
public class BDDPlanning {

    BDDPlanningHelper helper;
    SQLiteDatabase base;
    public void resetDatabase(){

        base.execSQL("drop table if exists service");
        base.execSQL("drop table if exists personne");



        //create database
        base.execSQL("CREATE TABLE service (_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)");
        base.execSQL("CREATE TABLE personne (_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT,prenom TEXT)");


        //jeux test
        base.execSQL("INSERT into service values (4,\"Entretien\")");
        base.execSQL("INSERT into personne values (1,\"jean paul\",\"raymond\")");
        base.execSQL("INSERT into personne values (2,\"louis\",\"pierre\")");
        base.execSQL("INSERT into personne values (3,\"paul\",\"laurent\")");
        base.execSQL("INSERT into personne values (4,\"hugo\",\"laurent\")");
        base.execSQL("INSERT into personne values (5,\"eric\",\"laurent\")");
        base.execSQL("INSERT into personne values (6,\"luc\",\"laurent\")");
        base.execSQL("INSERT into personne values (7,\"theodore\",\"laurent\")");
        base.execSQL("INSERT into personne values (8,\"yvan\",\"laurent\")");
        base.execSQL("INSERT into personne values (9,\"thierry\",\"laurent\")");

        base.execSQL("INSERT into personne values (10,\"david\",\"laurent\")");


    }

    public void open(Context activity) throws SQLException {
        helper = new BDDPlanningHelper(activity);
        base = helper.getWritableDatabase();


    }

    public Cursor getPersonnes(){
        this.resetDatabase();
        return base.rawQuery("select _id,name,prenom from personne",null);

    }

    public Cursor testInfos(){
        this.resetDatabase();
        return base.rawQuery("select _id,name from service",null);

    }
}
